package com.sgb.kjwl.viewmodel.manage;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.manage.AgentStaffCheckEntity;
import com.sgb.kjwl.view.event.self.AgentApplyEvent;
import com.sgb.kjwl.view.ui.fragment.manage.special.SpecialMenberNewFragment;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.event.EventConstant;
import com.swgk.core.util.MToast;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SpecialMenBerNewFragmentModel extends AndroidViewModel {
    public SpecialMenBerNewFragmentModel(@NonNull Application application) {
        super(application);
    }
    private SpecialMenberNewFragment menberNewFragment;
    //获取审核列表
    public void getlist(SpecialMenberNewFragment menberNewFragment,int page,int limit,String status){
        this.menberNewFragment =menberNewFragment;
        Map<String,Object> map =new HashMap<>();
        map.put("limit",limit);
        map.put("page",page);
        if (status.equals("0")){
            map.put("status","");
        }else {
            map.put("status",status);
        }

        APIManager.getInstance().getUserAPI().auditListByStatus(map).enqueue(new Callback<BaseEntity<ListResponse<List<AgentStaffCheckEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ListResponse<List<AgentStaffCheckEntity>>>> call, Response<BaseEntity<ListResponse<List<AgentStaffCheckEntity>>>> response) {
                   if (response.body()!=null){
                       if (response.body().isSuccess()){
                           menberNewFragment.setview(response.body().getData().getList());
                       }
                   }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<AgentStaffCheckEntity>>>> call, Throwable t) {

            }
        });
    }
    public void rejectAdd(Context context,String id,String rejecimark){
        Map<String,Object> map =new HashMap<>();
        map.put("id",id);
        map.put("rejectMark",rejecimark);
        APIManager.getInstance().getUserAPI().rejectAdd(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                        if (response.body()!=null){
                            AgentApplyEvent agentApplyEvent=new AgentApplyEvent();
                            agentApplyEvent.setMessageTag(EventConstant.EVENT_AGENT_APPLY_SUCCESS);
                            EventBus.getDefault().post(agentApplyEvent);
                            MToast.showToast(context, response.body().getMsg());
                        }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {

            }
        });
    }
}
